package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.model.product.SpuImage;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "商品SKU接口")
@RestController
@RequestMapping("admin/product")
public class SkuManageController {

    @Autowired
    private ManageService mangeService;

    //  /admin/product/saveSkuInfo
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){

        //  调用服务层方法：
        mangeService.saveSkuInfo(skuInfo);
        return Result.ok();
    }

    //  /admin/product/list/{page}/{limit}
    @GetMapping("list/{page}/{limit}")
    public Result getList(@PathVariable Long page,
                          @PathVariable Long limit){
        //创建一个page
        Page<SkuInfo> skuInfoPage = new Page<>(page, limit);
        //调用服务层方法
        IPage iPage = mangeService.getList(skuInfoPage);
        return Result.ok(iPage);
    }

    //  /admin/product/onSale/{skuId}
    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){
        //调用服务层方法
        mangeService.onSale(skuId);
        return Result.ok();
    }

    //  /admin/product/cancelSale/{skuId}
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){
        //调用服务层方法
        mangeService.cancelSale(skuId);
        return  Result.ok();
    }
}
